clear all 
set more off

cd  "D:\Dropbox\Tradeoff replication" 
log using Stata_log, replace

use "tradeoff_data.dta"
** randomly assigned officials
tab QK

*1 (CIT): corrupt-and-incompetent township leaders
*2 (CCT): corrupt-yet-competent township leaders
*3 (CIM): corrupt-and-incompetent municipal mayors
*4 (CCM): corrupt-yet-competent municipal mayors
*5 (HIT): honest-yet-incompetent township leaders
*6 (HCT): honest-and-competent township leaders
*7 (HIM): honest-yet-incompetent municipal mayors
*8 (HCM): honest-and-competent municipal mayors


** attribute: competence (0=incompetent; 1=competent)
tab competent 

** attribute: corruption (0=corrupt; 1= honest)
tab corrupt

** attribute: government levels (0= township; 1=municipality)
tab rank


*******************************************************
**********  Table 3: Demotion *************************
*******************************************************

quietly reg demotion i.QK, r
* show proportion in each cell
margins, over(QK) 

/*calculate column differenes*/

reg demotion i.QK if QK==1|QK==2,r 
reg demotion i.QK if QK==3|QK==4,r
reg demotion i.QK if QK==5|QK==6,r
reg demotion i.QK if QK==7|QK==8,r

/*row differences*/
reg demotion i.QK if QK==1|QK==5,r
reg demotion i.QK if QK==2|QK==6,r
reg demotion i.QK if QK==3|QK==7,r
reg demotion i.QK if QK==4|QK==8,r


********************************************************************************
********* Figure 1: Corrupt-yet-competent vs Honest-yet-incompetent officials **
********************************************************************************

*** Below shows the regression estimates **********
*** A separate R file draws Figure 1 (and Online Appendix Figure A) ************

/**(a) to (c)**/
quietly reg demotion i.QK,r
lincom 2.QK-5.QK

quietly  reg promotion i.QK,r
lincom 2.QK-5.QK

quietly  reg report i.QK,r
lincom 2.QK-5.QK

/**(d) to (f)**/
quietly reg demotion i.QK,r
lincom 4.QK-7.QK

quietly reg promotion i.QK,r
lincom 4.QK-7.QK

quietly reg report i.QK,r
lincom 4.QK-7.QK

/**(g) to (i)**/
quietly reg demotion i.QK,r
lincom (4.QK-7.QK)-(2.QK-5.QK)

quietly reg promotion i.QK,r
lincom (4.QK-7.QK)-(2.QK-5.QK)

quietly reg report i.QK,r
lincom (4.QK-7.QK)-(2.QK-5.QK)


**********************************************************
****************Manipulation check: footnotes 12 & 13 *****
**********************************************************
* check_corrupt: respondents view the assigned official as corrupt (0=no, 1=yes)
reg check_corrupt corrupt, r
margins, over(corrupt)

* footnote 12
reg check_corrupt corrupt##rank, r
margins, dydx(corrupt) over(rank)

* check_competent: respondents view the assigned official as competent (0=no, 1=yes)
reg check_competent competent, r
margins, over(competent)

* footnote 13
reg check_competent competent##rank, r
margins, dydx(competent) over(rank)


***************************************************
******** Online Appendix Table A: Balance *********
***************************************************

preserve
** For presentation, re-order official types so township level proceeds 
** municipality level in Appendix Table A
gen QK_order=.
/*township*/
replace QK_order=1 if QK==1 /*CIT*/
replace QK_order=2 if QK==2 /*CCT*/
replace QK_order=3 if QK==5 /*HIT*/
replace QK_order=4 if QK==6 /*HCT*/
/*municipal*/
replace QK_order=5 if QK==3 /*CIM*/
replace QK_order=6 if QK==4 /*CCM*/
replace QK_order=7 if QK==7 /*HIM*/
replace QK_order=8 if QK==8 /*HIM*/

label define QK_orders 1 "CIT" 2 "CCT" 3 "HIT" 4 "HCT" ///
5 "CIM" 6 "CCM" 7 "HIM" 8 "HCM"
label values QK_order QK_orders
tab QK_order
  
* F TESTS
mat Ftest = J(17, 11 ,0)

local j=1
qui foreach var of varlist male han age hedu income ccp urban localcity hukouu gov town_clean town_corrupt town_dtk municipal_clean municipal_corrupt municipal_dtk contact{
  summarize `var', detail
  mat Ftest[`j', 1]= r(min)
  mat Ftest[`j', 2]= r(max)
  
  reg `var' i.QK_order, r
  margins, over(QK_order) post
  mat Ftest[`j', 3]= r(b) 
  
  reg `var' i.QK_order, r
  test 2.QK_order=3.QK_order=4.QK_order=5.QK_order=6.QK_order=7.QK_order=8.QK_order=0
  mat Ftest[`j',11]= r(p)
  local j = `j'+1
}  

matrix colnames Ftest = min max CIT CCT HIT HCT HIM CCM HIM HCM pvalue
matrix rownames Ftest = "Male" "Han" "Age" "High education" "Annual income" ///
"Party member" "Urban residence" "Hometown (same municipality)" ///
"Urban hukou" "Government and public employee" "Township gov't_clean" "Township gov't_corrupt" /// 
"Township gov't_dtk" "Municipal gov't_clean" "Municipal gov't_corrupt" ///
"Municipal govt_dtk"  "Gov't interaction frequency"
mat list Ftest

putexcel set "balance.xlsx", sheet("Sheet1") replace
putexcel A1=matrix(Ftest), names 
restore



******************************************************
********* Online Appendix Table C: Promotion *********
******************************************************
quietly reg promotion i.QK, r

/*proportions in each cell*/
margins, over(QK)

/*column differences*/
reg promotion i.QK if QK==1|QK==2,r
reg promotion i.QK if QK==3|QK==4,r
reg promotion i.QK if QK==5|QK==6,r
reg promotion i.QK if QK==7|QK==8,r

/*row differences*/
reg promotion i.QK if QK==1|QK==5,r
reg promotion i.QK if QK==2|QK==6,r
reg promotion i.QK if QK==3|QK==7,r
reg promotion i.QK if QK==4|QK==8,r


******************************************************
********* Online Appendix Table D: Reporting *********
******************************************************
quietly reg report i.QK, r

/*proportions in each cell*/
margins, over(QK)

/*column differences*/
reg report i.QK if QK==1|QK==2,r
reg report i.QK if QK==3|QK==4,r
reg report i.QK if QK==5|QK==6,r
reg report i.QK if QK==7|QK==8,r

/*row differences*/
reg report i.QK if QK==1|QK==5,r
reg report i.QK if QK==2|QK==6,r
reg report i.QK if QK==3|QK==7,r
reg report i.QK if QK==4|QK==8,r


******************************************************
*********** Online Appendix Table E: AMCE ************
******************************************************

reg demotion corrupt competent rank, r
outreg2 using amce, excel symbol (***,**,*) alpha (0.01,0.05,0.1) dec (3) replace

reg promotion corrupt competent rank, r
outreg2 using amce, excel symbol (***,**,*) alpha (0.01,0.05,0.1) dec (3) append

reg report corrupt competent rank, r
outreg2 using amce, excel symbol (***,**,*) alpha (0.01,0.05,0.1) dec (3) append

reg demotion corrupt competent rank 1.corrupt#1.rank 1.competent#1.rank, r
outreg2 using amce, excel symbol (***,**,*) alpha (0.01,0.05,0.1) dec (3) append

reg promotion corrupt competent rank 1.corrupt#1.rank 1.competent#1.rank, r
outreg2 using amce, excel symbol (***,**,*) alpha (0.01,0.05,0.1) dec (3) append

reg report corrupt competent rank 1.corrupt#1.rank 1.competent#1.rank, r
outreg2 using amce, excel symbol (***,**,*) alpha (0.01,0.05,0.1) dec (3) append

** marginal effects conditional on the government levels
** AMCEs of corruption and competence at township level are available in the regression above 
** Differently, regression below use municipality-level as reference group, 
** so the coefficients of `corrupt' and `competent' represent their AMCEs at the municipality-level
reg demotion corrupt competent 0.rank 1.corrupt#0.rank 1.competent#0.rank, r
reg promotion corrupt competent 0.rank 1.corrupt#0.rank 1.competent#0.rank, r
reg report corrupt competent 0.rank 1.corrupt#0.rank 1.competent#0.rank, r



********************************************************************************
*****  Online Appendix Figure A: Replicating Figure 1 by adding controls *******
********************************************************************************

global reg_covar = "male han i.age hedu i.income ccp urban localcity hukouu gov town_clean town_corrupt municipal_clean municipal_corrupt i.contact"
* township_dtk and municipal_dtk are ommited as the reference groups

*** Below shows the regression estimates ***************************************
*** A separate R file draws Online Appendix Figure A (and Figure 1) ************

/**(a) to (c)**/
quietly reg demotion i.QK $reg_covar,r
lincom 2.QK-5.QK

quietly  reg promotion i.QK $reg_covar,r
lincom 2.QK-5.QK

quietly  reg report i.QK $reg_covar,r
lincom 2.QK-5.QK

/**(d) to (f)**/
quietly reg demotion i.QK $reg_covar,r
lincom 4.QK-7.QK

quietly reg promotion i.QK $reg_covar,r
lincom 4.QK-7.QK

quietly reg report i.QK $reg_covar,r
lincom 4.QK-7.QK

/**(g) to (i)**/
quietly reg demotion i.QK $reg_covar,r
lincom (4.QK-7.QK)-(2.QK-5.QK)

quietly reg promotion i.QK $reg_covar,r
lincom (4.QK-7.QK)-(2.QK-5.QK)

quietly reg report i.QK $reg_covar,r
lincom (4.QK-7.QK)-(2.QK-5.QK)


log close



